<template>
  <view>
    <!-- 遮罩层 -->
    <view 
      class="mask" 
      :class="{ show: visible }" 
      @tap="closeDrawer"
    ></view>
    
    <!-- 抽屉组件 -->
    <view 
      class="drawer" 
      :class="{ show: visible }" 
      @tap="stopPropagation"
    >
      <view class="drawer-header">
        <text class="drawer-title">{{ title }}</text>
        <view class="drawer-close" @tap="closeDrawer">
          <text>×</text>
        </view>
      </view>
      
      <view class="drawer-content">
        <slot></slot>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'RightDrawer',
  props: {
    title: {
      type: String,
      default: '抽屉标题'
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    closeDrawer() {
      this.$emit('close');
    },
    
    stopPropagation() {
      // 阻止事件冒泡，避免点击抽屉内容时关闭
    }
  }
}
</script>

<style scoped>
.mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 998;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.mask.show {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 500px;
  max-width: 90vw;
  background-color: white;
  z-index: 999;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -5px 0 15px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer.show {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px;
  background: #3498db;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.drawer-title {
  font-size: 1.3rem;
  font-weight: 600;
}

.drawer-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
</style>